package com.cloud.DrugManagement.service.Impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloud.DrugManagement.mapper.DrugPriceMapper;
import com.cloud.DrugManagement.mapper.SupplierMapper;
import com.cloud.DrugManagement.pojo.Supplier;
import com.cloud.DrugManagement.service.SupplierService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zhozixiong
 * @date 2023/02/08
 */
@Service
@RequiredArgsConstructor
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements SupplierService {

    private final int SIZE = 10;

    private final DrugPriceMapper drugPriceMapper;

    @Override
    public Page<Supplier> searchAllBySidOrSname(int pages,  Object parameter) {
        Page page = new Page(pages, SIZE);
        return baseMapper.searchAllBySidOrSname(page, parameter);
    }

    @Override
    public Supplier searchAllBySid(int sid) {
        return baseMapper.searchAllBySid(sid);
    }

    @Override
    public boolean delBySid(Integer sid) {
        //删除指定供应商的价格表
        drugPriceMapper.delBySid(sid);
        //删除指定供应商
        return baseMapper.delBySid(sid) >= 1;
    }

    @Override
    public boolean updateSnameBySid(String sname, int sid) {
        //修改供应商信息
        return baseMapper.updateSnameBySid(sname, sid) >= 1;
    }

    @Override
    public boolean insert(Supplier supplier) {
        return baseMapper.insert(supplier) >= 1;
    }
}
